package com.example.qxfw.backgroundManagement.controller;

import com.example.qxfw.backgroundManagement.service.MonitoringManagementService;
import com.example.qxfw.common.SysResult;
import com.example.qxfw.common.entity.CollectTime;
import com.example.qxfw.common.entity.PublishRecord;
import com.example.qxfw.rcyw.pojo.JobMake;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/************************************
 *
 * @author : HuangDeYin Jolly
 * @since : JDK 11
 * @Date : 2023/7/3  星期一   10:32
 * @description : 此类用来
 ***************************************/
@Api(tags = "后台管理-监控管理")
@RestController
@CrossOrigin
@RequestMapping("/monitoringManagement")
public class MonitoringManagementController {

    @Autowired
    private MonitoringManagementService monitoringManagementService;

    @ApiOperation("根据业务类型查询业务")
    @RequestMapping(value = "selectJobType")
    public SysResult selectJobType() {
        List<JobMake> jobMakes = this.monitoringManagementService.selectJobType();
        return SysResult.success(jobMakes);
    }

    @ApiOperation("初始化业务表")
    @RequestMapping(value = "selectInit")
    public SysResult selectInit() {
        List<JobMake> jobMakes = this.monitoringManagementService.selectAll();
        return SysResult.success(jobMakes);
    }

    @ApiOperation("判断业务是否已经做完")
    @RequestMapping(value = "selectRecentMakeTime")
    public SysResult selectRecentMakeTime(final String jobType, final String makeTimeChar) {
        List<JobMake> jobMakes = this.monitoringManagementService.selectRecentMakeTime(jobType, makeTimeChar);
        return SysResult.success(jobMakes);
    }

    @ApiOperation("查询采集时间")
    @RequestMapping(value = "selectCollectTime")
    public SysResult selectCollectTime(final String dispName, final String collectType) {
        List<CollectTime> collectTimes = this.monitoringManagementService.selectCollectTime(dispName, collectType);
        return SysResult.success(collectTimes);
    }

    @ApiOperation("查询发布记录")
    @RequestMapping(value = "selectPublicRecord")
    public SysResult selectPublicRecord() {
        List<PublishRecord> publishRecords = this.monitoringManagementService.selectPublicRecord();
        return SysResult.success(publishRecords);
    }

    @ApiOperation("根据type更新采集时间的state")
    @RequestMapping(value = "updateStateByType")
    public SysResult updateStateByType(final String type, final String state){
        Integer updateStateByType = this.monitoringManagementService.updateStateByType(type, state);
        return returnInformation("根据type更新采集时间的state", updateStateByType);
    }

    @ApiOperation("根据业务名称和业务类型查询最近制作时间")
    @RequestMapping(value = "selectByJobTypeAndJobName")
    public SysResult selectByJobTypeAndJobName(final String nameType, final String jobName){
        List<JobMake> jobMakes = this.monitoringManagementService.selectByJobTypeAndJobName(nameType, jobName);
        return SysResult.success(jobMakes);
    }

    @ApiOperation("根据产品名称和产品类型查询出发布记录")
    @RequestMapping(value = "selectByProduceNameAndProductType")
    public SysResult selectByProduceNameAndProductType(final String productName, final String productType){
        List<PublishRecord> publishRecords = this.monitoringManagementService.selectByProduceNameAndProductType(productName, productType);
        return SysResult.success(publishRecords);
    }

    @ApiOperation("根据业务名称查找业务类型")
    @RequestMapping(value = "selectJobName")
    public SysResult selectJobName(final String nameType){
        List<JobMake> jobMakes = this.monitoringManagementService.selectJobName(nameType);
        return SysResult.success(jobMakes);
    }


    public SysResult returnInformation(String info, Integer result) {
        if (result < 0) {
            return SysResult.fail(info + "失败");
        } else {
            return SysResult.success(result);
        }
    }

}
